//
//  HKUserInfoHeaderView.m
//  HKTimeKitApp
//
//  Created by huzhaoke1 on 2023/5/10.
//

#import "HKUserInfoHeaderView.h"
#import "HKCommonDefine.h"
#import "UIView+properties.h"
#import "HKFontHelper.h"
#import "UILabel+create.h"
#import <Masonry/Masonry.h>

static const CGFloat kKSLeftMargin = 24.f;
static const CGFloat kKSMiddleMargin = 9.f;

@interface HKUserInfoHeaderView ()

@property (nonatomic, strong) UIImageView *titleImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HKUserInfoHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.titleImgView];
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.lineView];
        
        [self.titleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kKSLeftMargin);
            make.centerY.mas_equalTo(self.contentView);
        }];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.titleImgView.mas_right).offset(kKSMiddleMargin);
            make.centerY.mas_equalTo(self.contentView);
        }];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kKSLeftMargin);
            make.right.mas_equalTo(self.contentView).offset(-kKSLeftMargin);
            make.height.mas_equalTo(1);
            make.bottom.mas_equalTo(self.contentView);
        }];
    }
    return self;
}

+ (CGFloat)cellHeightWithContent:(id)content {
    return 60.f;
}
- (void)updateContent:(id)content {
    HKUserInfoHeaderViewViewModel *viewModel = KSSAFE_CAST(content, HKUserInfoHeaderViewViewModel);
    [self.titleImgView setImage:[UIImage imageNamed:viewModel.imageName]];
    self.titleLab.text = viewModel.title;
}

#pragma mark - getter & setter
- (UIImageView *)titleImgView {
    if (!_titleImgView) {
        _titleImgView = [UIImageView new];
    }
    return _titleImgView;
}
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel labelWithFont:[HKFontHelper appcnBoldFontWithSize:16.f]
                                    bgColor:nil
                                  textColor:UIColorFromRGB(0x4448ff) textAligment:NSTextAlignmentRight];
    }
    return _titleLab;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = [UIColorFromRGB(0xb8b8b9) colorWithAlphaComponent:0.11];
    }
    return _lineView;
}

@end

@implementation HKUserInfoHeaderViewViewModel

@end
